package cn.gzsxt.music.mapper;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;

import cn.gzsxt.music.query.HitSongQueryObject;

@Mapper
public class HitSongProvider {
	
	public String getHitSongTotalByQo(HitSongQueryObject qo) {
		StringBuilder sql = new StringBuilder();
		sql.append("select count(*) from mc_song");
		if (qo.getSingerId() != null) {
			sql.append(" where singer_id = #{singerId} ");
						
		}else if (StringUtils.isNotBlank(qo.getHitSong())) {
			sql.append(" where song_id in (");
						
			String[] song_ids = qo.getHitSong().split(",");
			for (String song_id : song_ids) {
				sql.append("'");
				sql.append(song_id);
				sql.append("',");			
			}
			
			sql.deleteCharAt(sql.length()-1);
			sql.append(")");						
		}
		
		return sql.toString();
	}
		
	public String selectHitSongListByQo(HitSongQueryObject qo) {
		StringBuilder sql = new StringBuilder();
		sql.append("select * from mc_song");
		if (qo.getSingerId() != null) {
			sql.append(" where singer_id = #{singerId} ");
		
		}else if (StringUtils.isNotBlank(qo.getHitSong())) {
			sql.append(" where song_id in (");
			
			String[] song_ids = qo.getHitSong().split(",");
			for (String song_id : song_ids) {
				sql.append("'");
				sql.append(song_id);
				sql.append("',");			
			}
			
			sql.deleteCharAt(sql.length()-1);
			sql.append(")");		
		}		
		
		sql.append(" limit #{beginIndex},#{rows}");
		return sql.toString();
	}
	
}
